<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ include file="/pages/login/common.jsp" %>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description"/>
<meta content="B2B电商平台" name="keyword"/>

<title>B2B电商平台.平台活动添加商品</title>
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/style.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/btn.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/themes.css" />
<link rel="stylesheet" href="<%=path%>/include/JQuery zTree v3.4/css/demo.css">
<link rel="stylesheet" href="<%=path%>/include/JQuery zTree v3.4/css/zTreeStyle/zTreeStyle.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/register_icss.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/sweetalert/sweetalert.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/page.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/pagination/page.css" media="all">
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/mmt_trading.css" />

<script type="text/javascript" src="<%=path %>/include/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/icss.shop.manage.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/cookies.js"></script>
<script type="text/javascript" src="<%=path%>/include/pagination/jquery.pagination.js"></script>
<script type="text/javascript" src="<%=path%>/include/pagination/init.js"></script>
<script type="text/javascript" src="<%=path%>/include/JQuery zTree v3.4/js/jquery.ztree.core-3.4.js"></script>
<script type="text/javascript" src="<%=path%>/include/JQuery zTree v3.4/js/jquery.ztree.excheck-3.4.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/icss.common.js"></script>
<script type="text/javascript" src="<%=path %>/include/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript" src="<%=path %>/include/sweetalert/sweetalert-dev.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/doT.min.js"></script>

<style type="text/css">
body{}
td{font-size:12px;}
.table tr td {
	border-left: 1px solid #ddd;
	border-bottom: 1px solid #ddd;
	height: 33px;
}

.table tr th {
	border-left: 1px solid #ddd;
	font-weight: bold;
}
.noborder{border:none;height:2px;overflow:hidden;}
.noborder td{height: 2px;}
a:hover{background:none;}
</style>
<script type="text/javascript">
	$(function(){
		zTree = $.fn.zTree.init($("#treeDemo"), treeSetting);
	});
	
	var pagination;
	function _queryList(){
		var url = "<%=path %>/activityList/product_getNoAddProduct.do";
		var data = {
			categoryCode : $("#selectNodeId").val(),
			activityUuid : $("#activityUuid").val()
		};
		pagination = _initPagination({
			'pageId' : 'pagination',
			'url' : url,
			'data' : data,
			'rows' : 5,
			'callback' : _initDataList
		});
		}
	
	function _initDataList(data) {
 		var tpl = $('#dataTpl').html();
		$('#list_tbody').html(doT.template(tpl)(data.rows));
	 }
	
	//保存
	function saveProduct(){
		var activityUuid=$("#activityUuid").val();
		var productIds ="";
    	$("input[name='productId']").each(function(index,item){
    		 if($(this).attr("checked")=="checked"){
    			 productIds +=","+ $(this).val();
        	 }
	    });
	    productIds=productIds.substring(1);
	    if(productIds==""){
		    parent.swal("请至少选择一条记录!");
		    return;
		}else{
			$.ajax({
				type:"post",
				url: "<%=path %>/activityList/product_saveProduct.do",
				data:{"productIds":productIds,"activityUuid":activityUuid},
				dataType:"json",
				success:function(result){
					if (result.success == undefined) {
						result = eval('(' + result + ')');
					}
                    if(result.success){
                        parent.swal("添加成功!");
                    }
                    window.location.href="<%=path%>/activityList/product_toActivityProductListPage.do?activityUuid="+activityUuid;
				}
			});
			
		}
	}
	
	
</script>
</head>
<body class="theme-red" data-theme="theme-red">
	<div id="contentDiv">
		<div style="width:100%;height:30px;border-bottom:1px solid #ADADAD;margin-top:6px;">
 			<div class="toptil">
 				<a style="color: black;"  href="<%=path %>/activityList/activity_toActivityPage.do" >平台活动</a>→<a style="color: black;" href="<%=path%>/activityList/product_toActivityProductListPage.do?activityUuid=${activityUuid}">参与商品</a>→添加商品
 			</div>
 			<input type="hidden" id="activityUuid" name="activityUuid" value="${activityUuid }"/>
 		</div>
		<input type="hidden" id="selectNodeId" name="selectNodeId">
 		<input type="hidden" id="curPath" name="curPath" value="<%=path %>">
		<div style="width:100%;margin-top:10px;">
			<table style="width:100%;">
				<tr style="width:100%;height:26px;">
					<td style="width:25%;" nowrap>&nbsp;</td>
					<td style="width:1%;">&nbsp;</td>
					<td style="width:70%;vertical-align:top;text-align:right;">
						<div style="width:100%;">
							<a onclick="saveProduct();" class="btn" style="text-decoration:none;">保存</a>
						</div>
					</td>
				</tr>				
				<tr style="width:100%;">
					<td style="width:25%;vertical-align:top;" nowrap>
						<table id="deptTable">
							<thead>
							</thead>
							<tbody>
								<tr>
									<td> 
										<div style="height:400px;width:100%;overflow-x: hidden;overflow-y:auto;">
											<ul id="treeDemo" class="ztree" style="margin-top:0;background-color:#fff;border:1px #ccc solid;"></ul>
										</div>
									</td>
								</tr>
							</tbody>
						</table>
					</td>
					<td style="width:1%;">&nbsp;</td>
					<td style="width:70%;vertical-align:top;">
						<div>
                          	<table id="list_table" class="table" style="width:100%;">
								<thead>
									<tr class="list_table_title_tr" style="margin-top:10px;">
										<th class="span5" style="text-align:center;" nowrap> 选择 </th>
										<th class="span20" style="text-align:center;" nowrap> 商品图片 </th>
										<th class="span20" style="text-align:center;" nowrap> 商品名称 </th>
										<th class="span15" style="text-align:center;" nowrap> 商品类型 </th>
										<th class="span20" style="text-align:center;" nowrap> 商品价格 </th>
										<th class="span20" style="text-align:center;" nowrap> 下架时间 </th>
									</tr>
								</thead>
								<tbody id="list_tbody">
								</tbody>
							</table>
							<br/>
							<div class="dataTables_paginate paging_full_numbers">
							</div>
							<div id="pagination"></div>	
						</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
</body>
 <script type="text/javascript">
  	$(document).ready(function(){
		_reHeight();
	});
	function _reHeight(){
		var main = $(window.parent.document).find("#rightFrame");
		var mainheight = $("#contentDiv").height();
		main.height(mainheight);
	}
  	var zTree = null;
	/* 
	 * 下拉树的设置 
	 */  
	var treeSetting = {  
	    view: {  
	        dblClickExpand: false  
	    },  
		data: {  
			simpleData: {  
			    enable: true,
			    rootPId: 0
			}  
		},
		async:{
			enable: true,//设置ztree是否开启异步加载模式
			showLine: true ,//设置是否显示连接线
			type: "post",//post方式请求数据
			url: getUrl,//数据请求url
			autoParam:["id","name"],//异步加载时需要自动提交父节点属性的参数
			otherParam:{"otherParam":"zTreeAsyncTest"},
			dataFilter: filter
		},
		callback: {
			onClick: onClick,//点击节点
			onAsyncError : zTreeOnAsyncError,//加载失败
			onAsyncSuccess: zTreeOnAsyncSuccess//加载完成
		}
	}; 
	
	function getUrl(){
		var url = "<%=path %>/activityList/product_getTree.do";
		return url;
	}
	
	/* 
	 * 点击事件 
	 */  
	function onClick(e, treeId, treeNode) {
	    var zTree = $.fn.zTree.getZTreeObj("treeDemo");  
	    nodes = zTree.getSelectedNodes();  
	    treeNode = nodes[0];
		$("#selectNodeId").val(treeNode.id);
		_queryList();
	} 
	
	
	//过滤函数  
    function filter(treeId, parentNode, childNodes) {  
        if (!childNodes)  
            return null;  
        for ( var i = 0, l = childNodes.length; i < l; i++) {  
            //childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');  
        }  
        return childNodes;  
    }  
    //加载完成
	var firstAsyncSuccessFlag = 0;
	function zTreeOnAsyncSuccess(event, treeId, msg) {
		if (firstAsyncSuccessFlag == 0) {
        	try {
				//调用默认展开第一个结点
				var nodes = zTree.getNodes();
				zTree.expandNode(nodes[0], true);
				$("#tree_1_a").click();
	            
	            //异步加载完成再折叠所有子节点
	     //       var nodes = zTree.getNodes();
		//		if (nodes.length>0) {
		//			var index = zTree.getNodeIndex(nodes[0]);
		//			var rootNode = nodes[0];
		//			zTree.expandNode(rootNode, false, true, null, true);
		//		}
	            
	            firstAsyncSuccessFlag = 1;
        	} catch (err) {
	              
         	}
    	}
	}
	//加载失败提示  
    function zTreeOnAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {  
        alert("加载错误：" + XMLHttpRequest);  
    }; 
  </script>
  <script id="dataTpl" type="text/template">
		{{ for (var i = 0; i < it.length; i ++) { }}  
		{{     var row = it[i]; }}
			<tr style='line-height: 20px;white-space: nowrap;'>
				<td style='text-align:center;vertical-align: middle;'>
					<input type='checkbox' name='productId' value='{{=row.productId}}' star='3' mainpro=''>
				</td>
				<td style='text-align:center;vertical-align: middle;'>
					<img src='{{=row.productPic}}' width='50' height='50' alt='' resizeimg='true' onmousedown='' onerror='javascript:this.src="<%=path%>/download/error/nopicture.jpg"' style='width: 50px; height: 43.5px;'>
				</td>
				<td style='text-align:left;vertical-align: middle;'>{{=row.productName}}</td>
				<td style='text-align:center;vertical-align: middle;'>{{=row.categoryName}}</td>
				<td style='text-align:right;vertical-align: middle;'>{{=row.productPrice}}</td>
				<td style='text-align:center;vertical-align: middle;'>{{=row.downTime}}</td>
		     </tr>
		{{ } }}
	</script>
</html>
